package com.xx.job.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.job.common.PageResult;
import com.xx.job.controller.dto.PageDTO;
import com.xx.job.entity.system.SysLoginLog;
import com.xx.job.mapper.SysLoginLogMapper;
import com.xx.job.service.system.SysLoginLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@Service
public class SysLoginLogServiceImpl extends ServiceImpl<SysLoginLogMapper, SysLoginLog> implements SysLoginLogService {

    @Autowired
    private SysLoginLogMapper sysLoginLogMapper;

    @Override
    public int add(SysLoginLog sysLoginLog) {
        return sysLoginLogMapper.insert(sysLoginLog);
    }

    @Override
    public int delete(Long id) {
        return sysLoginLogMapper.deleteById(id);
    }

    @Override
    public int update(SysLoginLog sysLoginLog) {
        return sysLoginLogMapper.updateById(sysLoginLog);
    }

    @Override
    public SysLoginLog select(Long id) {
        return sysLoginLogMapper.selectById(id);
    }

    @Override
    public PageResult selectPage(PageDTO pageDTO, SysLoginLog sysLoginLog) {
        IPage<SysLoginLog> page = new Page<>(pageDTO.getPageIndex(),pageDTO.getPageSize());
        QueryWrapper<SysLoginLog> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(sysLoginLog.getIpaddr())){
            wrapper.like("ipaddr",sysLoginLog.getIpaddr().trim());
        }
        if(StringUtils.isNotBlank(sysLoginLog.getUsername())){
            wrapper.like("username",sysLoginLog.getUsername().trim());
        }
        if(StringUtils.isNotBlank(sysLoginLog.getStatus())){
            wrapper.eq("status",sysLoginLog.getStatus());
        }
        IPage<SysLoginLog> sysLoginLogIPage = sysLoginLogMapper.selectPage(page, wrapper);
        return new PageResult<SysLoginLog>(sysLoginLogIPage);


    }
}
